package cn.edu.zafu.bigdata.yeshuchang.wlbc;

import java.io.*;
import java.net.*;

public class TimeClient {
    public static void main(String[] args) {
        try {
            DatagramSocket clientSocket = new DatagramSocket();
            String serverAddress = "192.168.16.55";
            int serverPort = 12345; // 服务端端口号

            String sentence = "What is the current time?";
            byte[] sendData = sentence.getBytes();
            byte[] receiveData = new byte[1024];

            InetAddress IPAddress = InetAddress.getByName(serverAddress);

            DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, serverPort);
            clientSocket.send(sendPacket);

            DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            clientSocket.receive(receivePacket);
            String response = new String(receivePacket.getData(), 0, receivePacket.getLength());
            System.out.println("From server: " + response);

            clientSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}